#include<learning.h>

char* getcwd(char*,size_t);
int chdir(const char *path);
int mkdir(const char *pathname,mode_t mode);
int rmdir(const char *pathname);

DIR *opendir(const char* name);
struct dirent *readdir(DIR *dir);
void rewinddir(DIR *dir);
void seekdir(DIR *dir,off_t offset);
off_t telldir(DIR *dir);
int closedir(DIR * dir);

int stat(const char *pathname,struct stat *buf);
int printDir(char * path,int dep)
{		
	DIR * curDir = opendir(path);
	RET_CHECK(curDir,NULL,"opendir");
	char pathbuf[1024] = {0};
	struct dirent *curNode;
	while((curNode = readdir(curDir))!=NULL)
	{
		if(strcmp(curNode->d_name,".") == 0 ||strcmp(curNode->d_name,"..") == 0)
		{
			continue;
		}	
		printf("%*s %s\n",dep," ",curNode->d_name);
		if(curNode->d_type == 4)
		{
			sprintf(pathbuf,"%s%s%s",path,"/",curNode->d_name);
		
			printDir(pathbuf,dep+4);
		}
	}
return 0;
}
int main(int argc ,char **argv){


	ARGS_CHECK(argc,2);
	printDir(argv[1],0);
		
	return 0;
}
